#include "stdafx.h"
#include "player.h"
#include <model/mage.h>
#include <model/scene.h>
#include <model/wrappers/worldproxy.h>
#include <model/wrappers/selfcontrol.h>

Player::Player(IPlayerControl *control, const QString &name) :
    _control(control),
    _name(name),
    _points(0),
    _mage(0)
{
}

Player::~Player()
{
}

const QString &Player::name() const
{
    return _name;
}

int Player::points() const
{
    return _points;
}

Mage *Player::playerMage() const
{
    return _mage;
}

void Player::increasePoints(int value)
{
    if (value > 0)
        _points += value;
}

void Player::setMage(Mage *mage)
{
    _mage = mage;
}

ISelfControl::Action Player::askControl(const Scene *scene)
{
    ISelfControl::Action ret;

    WorldProxy world(scene, _mage);
    world.renewSelfControl();
    _control->process(&world);
    // apply ISelfControl data
    {
        auto self = dynamic_cast<const SelfControl*>(world.getSelfControl());
        ret = self->action();
        if (_pauseHandler.getActionPause(ret) == 0)
            _pauseHandler.setFullPause(ret);
        else
            ret = ISelfControl::Action_None;

        _mage->accept(self);
    }

    return ret;
}
